﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class EditResult : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitDate();
        }
    }

    //初始化数据
    void InitDate()
    {
        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            var pros = from r in dc.ProjectDetails
                       join a in dc.Approal on r.ApprovalNumber equals a.ID
                       where r.Project_ID == Request.QueryString["PID"]
                       select new
                       {
                           FDate = r.FinishDate,
                           PP = r.Project_Performance,
                       };
            foreach (var pro in pros)
            {
                
                if (pro.FDate != null && pro.PP != null)
                {
                    deTime.Text = pro.FDate.ToString().Substring(0, 10);
                    txtReusltDes.Text = pro.PP.ToString();
                }
                else if (pro.FDate != null && pro.PP == null)
                {
                    deTime.Text = pro.FDate.ToString().Substring(0, 10);
                    txtReusltDes.Text = "";
                }
                else
                {
                    deTime.Text = "";
                    txtReusltDes.Text = "";
                }

            }
        }
    }

    //完成
    protected void btnOK_Click(object sender, EventArgs e)
    {
        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            var pro = dc.ProjectDetails.Select(p => p)
                   .Where(p => p.Project_ID == Request.QueryString["PID"])
                   .SingleOrDefault();
            if (deTime.Text.ToString() == "")
            {
                Frame.Global.GlobalFunctions.Alert("请选择完成时间");
            }
            else
            {
                pro.FinishDate = Convert.ToDateTime(deTime.Text.ToString());
                pro.Project_Performance = txtReusltDes.Text.ToString();
                dc.SubmitChanges();
                Response.Redirect("ProResult.aspx");
            }
        }
    }
}